home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / turlvie2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  4.9 KB  |  177 lines

  1. //    Copyright (c) 1993, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        TURLView
  4. //    Include File:    turlview.h
  5. //    Purpose:    Provide the view of a URL
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        12-27-93    created
  9. //        02-02-94    Began a major revision to fully handle a
  10. //                multiple document interface with WWW, take
  11. //                over the formatting and drawing of the
  12. //                old gridtext functions of HText, and optimize
  13. //                memory usage, selecting anchors, the usage of
  14. //                HText's new image file.  See gridtext.
  15. //        02-09-94    Split all members into seperate files.
  16. #define Uses_TProgram
  17. #include"turlview.h"
  18. #include"trace.h"
  19. #include"globals.h"
  20. extern "C"    {
  21. #include"image.h"
  22. };
  23.  
  24. TURLView::TURLView(const TRect& TR_bounds, TScrollBar *TSBp_x,
  25.     TScrollBar *TSBp_y, const char *cp_URL, const char *cp_Index) :
  26.     TScroller(TR_bounds, TSBp_x, TSBp_y)    {
  27. //    Purpose:    Constructor of a URL view
  28. //    Arguments:    TR_bounds    The rectangle of the view.
  29. //            TSB_x        The horizontal scroll bar, 0 if none.
  30. //            TSB_y        The vertical scroll bar, 0 if none.
  31. //            cp_URL        The URL to load into the view.
  32. //    Remarks/Portability/Dependencies/Restrictions:
  33. //    Revision History:
  34. //        12-27-93    created
  35. //        02-22-94    Modified so the rendered file is opened and
  36. //                left open until view is destroyed.
  37.  
  38. #ifndef RELEASE
  39.     trace("Creating view.");
  40. #endif // RELEASE
  41.  
  42.     //    Set this view to be the current globally.
  43.     ::TURLV_current = this;
  44.  
  45.     //    No temporary file yet.
  46.     fsp_temp = NULL;
  47.  
  48.     //    We don't have an image to display yet.
  49.     cp_imagename = NULL;
  50.  
  51.     //    So far, we are valid.
  52.     B_valid = True;
  53.  
  54.     //    This isn't a download, yet.
  55.     B_download = False;
  56.  
  57.     //    Set our hyperdocument, temp file, and selected anchor to
  58.     //    nothing.
  59.     HTp_HyperDoc = NULL;
  60.     TAp_selected = NULL;
  61.     TTNp_temp = NULL;
  62.     HTCAp_2BSelected = NULL;
  63.  
  64.     //    Haven't performed a search in this view yet.
  65.     usi_lastSearchLine = usi_lastSearchOffset = 0U;
  66.     TAp_search = NULL;
  67.  
  68.     //    Create our line and anchor collection.
  69.     //    The line collection limit and delta are so big, because
  70.     //    the collections seem to fail after many inserts.  By raising
  71.     //    these numbers, it seems the collection has a longer life.
  72.     //    Some files have a large number of lines.
  73.     //    Try http://kufacts.cc.ukans.edu:8002/cwis/user.listing
  74.     TNSCp_lines = new TNSCollection(200, 200);
  75.     TNSCp_anchors = new TNSCollection(10, 10);
  76.     if(TNSCp_lines == NULL || TNSCp_anchors == NULL)    {
  77.         B_valid = False;
  78.     }
  79.     else    {
  80.         //    Define how our view can grow.
  81.         growMode = gfGrowHiX | gfGrowHiY;
  82.  
  83.         //    Load the url.
  84.         auto Boolean B_considerValid = loadURL(cp_URL, cp_Index);
  85.  
  86.         //    We possibly now hold an image filename.
  87. #ifndef RELEASE
  88.         trace("Checking for image.");
  89. #endif // RELEASE
  90.         if(cp_imagename != NULL)    {
  91.             //    We have to inform our DosLynx that there
  92.             //    is an image to display after we are destroyed.
  93.             //    It will be up to other DosLynx code to free
  94.             //    the cp_imagename string.
  95. #ifndef RELEASE
  96.             trace("Image " << cp_imagename << " found.");
  97. #endif // RELEASE
  98.             TEvent TE_image;
  99.  
  100.             TE_image.what = evCommand;
  101.             TE_image.message.command = cmImage;
  102.             TE_image.message.infoPtr = (void *)cp_imagename;
  103.  
  104.             TProgram::application->handleEvent(TE_image);
  105.             return;
  106.         }
  107.  
  108.         if(B_valid != False)    {
  109.             B_valid = B_considerValid;
  110.         }
  111.  
  112.         //    If loaded a HText.
  113.         if(B_valid == True)    {
  114. #ifndef RELEASE
  115.             trace("Successful load being rendered to file.");
  116. #endif // RELEASE
  117.             //    Set the HText to know how many views are
  118.             //    looking at it.  This will avoid the HText
  119.             //    from being freed if we surpass the loaded
  120.             //    limit.
  121.             HTp_HyperDoc->usi_Views++;
  122.  
  123.             //    Create the temporary file object.
  124.             TTNp_temp = new TTempName(cp_TempDir);
  125.             if(TTNp_temp == NULL)    {
  126.                 B_valid = False;
  127.             }
  128.             else    {
  129.                 //    Next, we format the document exactly
  130.                 //    for the view.
  131.                 FormatHTML();
  132.  
  133.                 //    Open the rendered file, and leave
  134.                 //    open until the window is closed.
  135.                 fsp_temp = new fstream(TTNp_temp->getName(),
  136.                         ios::in | ios::binary |
  137.                         ios::nocreate);
  138.                 if(fsp_temp == NULL)    {
  139.                     doslynxmessage("Unable to open "
  140.                         "rendered file " <<
  141.                         TTNp_temp->getName());
  142.                     B_valid = False;
  143.                 }
  144.  
  145.                 //    If there is a selected anchor from
  146.                 //    the start, then we must adjust the
  147.                 //    view to begin drawing at that
  148.                 //    anchor.
  149.                 if(TAp_selected != NULL)    {
  150.                     //    Find the line the anchor is
  151.                     //    in.
  152.                     for(delta.y = 0; delta.y < TNSCp_lines
  153.                         ->getCount(); delta.y++)
  154.                     {
  155.                         if(TAp_selected->getBegin() <=
  156.                             (signed long int)
  157.                             (TNSCp_lines->
  158.                             at(delta.y)))    {
  159.                             break;
  160.                         }
  161.                     }
  162.                 }
  163.                 //    Otherwise, select the first anchor,
  164.                 //    if there is one.
  165.                 else    {
  166.                     if(TNSCp_anchors->getCount() != 0)
  167.                     {
  168.                         TAp_selected =
  169.                             (TextAttribute *)
  170.                             (TNSCp_anchors->at(0));
  171.                     }
  172.                 }
  173.             }
  174.         }
  175.     }
  176. }
  177.